package march.test_3_16;

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt(); // 读取要判断的员工号数量
        scanner.nextLine(); // 读取换行符

        for (int i = 0; i < n; i++) {
            String employeeNumber = scanner.nextLine(); // 读取每个员工号
            System.out.println(validateEmployeeNumber(employeeNumber) ? "yes" : "no");
        }

        scanner.close();
    }

    public static boolean validateEmployeeNumber(String employeeNumber) {
        // 检查长度是否为8位
        if (employeeNumber.length() != 10) {
            return false;
        }

        // 提取各部分
        String yearSuffix = employeeNumber.substring(0, 2);
        String month = employeeNumber.substring(2, 4);
        String day = employeeNumber.substring(4, 6);
        String uniqueNumber = employeeNumber.substring(6,10);


        // 转换为整数
        long fullNumber = Long.parseLong(employeeNumber);

        // 检查年份是否在1970到2023之间
        int year = 1900 + Integer.parseInt(yearSuffix);
        if (year < 1970 || year > 2023) {
            return false;
        }

        // 检查月份和日期是否合法
        if (month.compareTo("00") < 0 || month.compareTo("12") > 0 ||
                day.compareTo("00") < 0 || day.compareTo("31") > 0) {
            return false;
        }

        int d = Integer.parseInt(day);

        // 根据月份检查日期是否合法
        switch (month) {
            case "04":
            case "06":
            case "09":
            case "11":
                if (d <= 0 || d > 30) {
                    return false;
                }
                break;
            case "02":
                // 检查闰年
                if ((year % 4 == 0 && year % 100 != 0) || year % 400 == 0) {
                    if (d <= 0 || d > 29) {
                        return false;
                    }
                } else {
                    if (d <= 0 || d > 28) {
                        return false;
                    }
                }
                break;
            default: if(d <= 0 || d > 31) return false;
        }

        // 检查整个十位的员工号是否可以被13整除
        return fullNumber % 13 == 0;
    }
}
